import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { AppController } from './app.controller';
import { AppService } from './app.service';
// import { UserModule } from './modules/user/user/user.module';
import { PhotoModule } from './photo/photo.module';
import { LoggerMiddleware } from './middleware/logger.middleware';
import { ResponseInterceptor } from './interceptors/response.interceptor';
import { GlobalExceptionFilter } from './interceptors/global-exception.filter';
import { DatabaseModule } from './database/database.module'
import { ConfigModule } from '@nestjs/config';
import { ScheduleModule } from '@nestjs/schedule';
import { TasksService } from './tasks/tasks.service';
import { BackupService } from './backup/backup.service';
// import { EmailService } from './email/email.service';
import { AuthModule } from './auth/auth.module';
import { JwtAuthGuard } from './auth/guards/jwt-auth.guard';
import { JwtService } from './auth/services/jwt.service';
import { RedisService } from './redis/redis.service';

@Module({
  imports: [ConfigModule.forRoot({ isGlobal: true }),
  ScheduleModule.forRoot(), PhotoModule, DatabaseModule, AuthModule],
  controllers: [AppController],
  providers: [
    AppService,
    LoggerMiddleware,
    JwtService,
    {// 全局身份验证拦截器
      provide: APP_GUARD,
      useClass: JwtAuthGuard
    },
    TasksService, BackupService,
    {// 全局异常拦截器
      provide: APP_FILTER,
      useClass: GlobalExceptionFilter,
    },
    {// 全局成功拦截器
      provide: APP_INTERCEPTOR,
      useClass: ResponseInterceptor,
    },
    RedisService
  ],
})
// implements NestModule Nest.js 框架中的一个接口,它允许您在模块（Module）中配置一些额外的功能和行为。
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(LoggerMiddleware).forRoutes('*');
  }
}